package com.gly091020.GLYCan.util;

import net.minecraft.core.NonNullList;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemContainerContents;
import org.jetbrains.annotations.NotNull;

public class CanItemContainer implements CanContainer {
    private final ItemStack stack;
    NonNullList<ItemStack> item = NonNullList.withSize(
            10,
            ItemStack.EMPTY
    );;
    public CanItemContainer(ItemStack stack) {
        super();
        this.stack = stack;
        ItemContainerContents contents = stack.getOrDefault(DataComponents.CONTAINER, ItemContainerContents.EMPTY);
        contents.copyInto(getItems());
    }

    @Override
    public void setChanged() {
        this.stack.set(DataComponents.CONTAINER, ItemContainerContents.fromItems(this.getItems()));
    }

    @Override
    public @NotNull NonNullList<ItemStack> getItems() {
        return item;
    }
}
